package com.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/loginCheck")
public class LoginServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //接收数据
        String uname = req.getParameter("username");
        String pwd = req.getParameter("passpwd");

        resp.setContentType("text/html;charset=utf-8");

        PrintWriter out = resp.getWriter();

        //验证
        if(uname != null && uname.length() >0 && pwd !=null && pwd.length()>0) {
            if(uname.equals("abc") && pwd.equals("123")) {
                out.println(uname+":欢迎你");
            }else {
                out.println("用户名或者密码不正确");
            }
        } else {
            out.println("用户名或密码为空，请重新输入");
        }




    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
